/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.brain.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.brain.entity.BQuarterData;
import com.thinkgem.jeesite.modules.brain.service.BQuarterDataService;

/**
 * 季度表Controller
 * @author 程展峰
 * @version 2021-09-18
 */
@Controller
@RequestMapping(value = "${adminPath}/brain/bQuarterData")
public class BQuarterDataController extends BaseController {

	@Autowired
	private BQuarterDataService bQuarterDataService;
	
	@ModelAttribute
	public BQuarterData get(@RequestParam(required=false) String id) {
		BQuarterData entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bQuarterDataService.get(id);
		}
		if (entity == null){
			entity = new BQuarterData();
		}
		return entity;
	}
	
	@RequiresPermissions("brain:bQuarterData:view")
	@RequestMapping(value = {"list", ""})
	public String list(BQuarterData bQuarterData, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BQuarterData> page = bQuarterDataService.findPage(new Page<BQuarterData>(request, response), bQuarterData); 
		model.addAttribute("page", page);
		return "modules/brain/bQuarterDataList";
	}

	@RequiresPermissions("brain:bQuarterData:view")
	@RequestMapping(value = "form")
	public String form(BQuarterData bQuarterData, Model model) {
		model.addAttribute("bQuarterData", bQuarterData);
		return "modules/brain/bQuarterDataForm";
	}

	@RequiresPermissions("brain:bQuarterData:edit")
	@RequestMapping(value = "save")
	public String save(BQuarterData bQuarterData, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bQuarterData)){
			return form(bQuarterData, model);
		}
		bQuarterDataService.save(bQuarterData);
		addMessage(redirectAttributes, "保存季度表成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bQuarterData/?repage";
	}
	
	@RequiresPermissions("brain:bQuarterData:edit")
	@RequestMapping(value = "delete")
	public String delete(BQuarterData bQuarterData, RedirectAttributes redirectAttributes) {
		bQuarterDataService.delete(bQuarterData);
		addMessage(redirectAttributes, "删除季度表成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bQuarterData/?repage";
	}

}